package com.fw.render;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fw.core.Const;

public abstract class Render implements Serializable {

	private static final long serialVersionUID = 5785522236870843475L;
	protected String view;
	protected transient HttpServletRequest request;
	protected transient HttpServletResponse response;

	private transient static String encoding = Const.DEFAULT_ENCODING;
	private transient static boolean devMode;

	static final void init(String encoding, boolean devMode) {
		Render.encoding = encoding;
		Render.devMode = devMode;
	}

	public static final String getEncoding() {
		return encoding;
	}

	public static final boolean getDevMode() {
		return devMode;
	}

	public final Render setContext(HttpServletRequest request, HttpServletResponse response) {
		this.request = request;
		this.response = response;
		return this;
	}

	public final Render setContext(HttpServletRequest request, HttpServletResponse response, String viewPath) {
		this.request = request;
		this.response = response;
		if (view != null && !view.startsWith("/"))
			view = viewPath + view;
		return this;
	}

	public String getView() {
		return view;
	}

	public void setView(String view) {
		this.view = view;
	}

	public abstract void render();
}
